<h3 class="page-header">Thêm tự dộng dang duợc hoàn tất</h3>
<div class="row">
    <div class="col-md-6">
        đang chạy dữ liệu
    </div>
</div>
<?php
    if($_POST['submit']){
        $webinput   = $_POST['webinput'];
        $link       = $_POST['link'];
        if($webinput && $link){
            if($webinput == 1){
                // conecting database
                conectingDatabase();
                // load library simple html dom
                require_once "simplehtmldom/simple_html_dom.php";
                $news = array();
                $url = $link;
                $html = file_get_html($url);
                $count = 0;
                foreach($html->find('li.item .title a') as $title){
                    $news[]['title'] = $title->plaintext;
                }
                foreach($html->find('li.item .title a') as $title){
                    $news[$count]['href'] = $title->href;
                    $content_html = file_get_html("http://kenh14.vn".$title->href);
                    foreach($content_html->find('.content') as $contents){
                        $news[$count]['content'] = $contents->innertext;
                    }
                    $count ++;
                }
                $count = 0;
                foreach($html->find('li.item div.img a img') as $title){
                    $news[$count]['src'] = $title->src;
                    $count ++;
                }
                $count = 0;
                foreach($html->find('li.item .sapo') as $title){
                    $news[$count]['summary'] = $title->plaintext;
                    $count ++;
                }
                // insert database
                foreach($news as $new){
                    $link_seo = seo_url($new['title']);
                    $content_insert = addslashes($new['content']);
                    $sql  = "INSERT INTO app_dl (idcat,name, url, title, brief, content, photo)";
                    $sql .= " VALUES (6,'".$new['title']."','".$link_seo."','".$new['title']."','".$new['summary']."','".$content_insert."'
                    ,'".$new['src']."')";
                    mysql_query($sql);
                }                 
                // close conecting
                closeDB();
            }
        }
    }
?>